package br.com.peperoncino.controller;

import java.io.FileInputStream;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import br.com.peperoncino.utils.HibernateUtil;

public class PeperoncinoView extends Application{

	public static void main(String[] args) {
		Application.launch(PeperoncinoView.class, (String[]) null);
	}

	@Override
	public void start(Stage palco) throws Exception {
		
		HibernateUtil.getSessionFactory(); 
		
		try {
			
			Locale.setDefault(new Locale("pt","Br"));
			
			FXMLLoader loader = new FXMLLoader(PeperoncinoView.class.getResource("Peperoncino.fxml"));
			AnchorPane page = (AnchorPane) loader.load();
			Scene scene = new Scene(page);
			palco.setScene(scene);
			palco.setTitle("Sistema Peperoncino");
			PeperoncinoController peperoncinoController = (PeperoncinoController) loader.getController();
			peperoncinoController.setStage(palco);

			Image img = new Image(new FileInputStream(System.getProperty("user.dir")+ "\\resources\\images\\saopaulo.png"));
			palco.getIcons().add(img);  
			palco.show();
		
		} catch (Exception e) {
			Logger.getLogger(PeperoncinoView.class.getName()).log(Level.SEVERE, null, e);
		}
		
	}
	
	@Override
	public void stop() throws Exception {
		super.stop();
		HibernateUtil.getSessionFactory().close(); 
	}
	
 }